<template>
  <div class="app-container">
    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="concerts"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row
    >
      <el-table-column prop="name" label="演唱会名称" width="160" />

      <el-table-column prop="place" label="举办地点" />
      <el-table-column prop="bandName" label="乐队" width="110" />

      <el-table-column
        prop="createTime"
        label="举办时间"
        type="datetime"
        width="160"
      >
      </el-table-column>

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="cancelConcert(scope.row.id)"
            >取消报名</el-button
          >
        </template></el-table-column
      ></el-table
    >
  </div>
</template>
      <script>
//引入js文件
import { getAttendedConcerts, updateAttendStatus } from "@/api/concert";
import { getToken } from "@/utils/auth";
export default {
  data() {
    return {
      listLoading: true, //是否显示“数据加载中这几个字”
      concerts: [], //封装返回的数据
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //分页查询
    getList() {
      let userId = getToken();
      getAttendedConcerts(userId)
        .then((res) => {
          this.concerts = res.data.rows;
          this.listLoading = false; //将“数据加载中”这几个字关掉
        })
        .catch((error) => {
          console.log(error);
        });
    },
    cancelConcert(id) {
      //删除方法
      //提示信息
      this.$confirm("确定不参加此演唱会了吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let userId = getToken();
          //调用删除方法
          updateAttendStatus(userId, id).then((res) => {
            this.$message.success("取消成功");
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
    
    <style>
.form-container {
  display: flex;
  justify-content: flex-end;
}
</style>